<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Language" content="zh-CN" />
<title>生成MD5值 >> Java就是老大</title>
<meta name="keywords" content="Java,J2EE,Javascript,CSS,HTML" />
<meta name="description" content="生成MD5值和测试生成的MD5." />
<meta name="Robots" content= "all">
<link rel="icon" type="image/x-icon" href="/favicon.ico" />
<link href="/style.css" rel="stylesheet" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script src="/js/plus.js"></script>
<script src="/js/md5.min.js" language="javascript" type="text/javascript"></script>
<script language="javascript" type="text/javascript">
	//生成md5
	function compose(str,key){
		//hex_md5(str)十六进制md5值；b64_md5(str)64位编码 
		if (key=='1'){
			$('#md5value').html(hex_md5(str));//把生成的十六进制md5值写入lable
		}
		else{
			$('#md5value').html(b64_md5(str));//把生成的64位编码md5值写入lable
		}
	}
	//对比是否和真正的md5值相同
	function verify(md5_obj){
		var val = $('#md5value').text(); //得到lable的值
		var md5 = md5_obj.value; 
		md5 = md5.replace(/(^\s*)|(\s*$)/g, ""); //去除两头空格
		if(val!=""){
			alert((md5==val)?"haha,same value":"oh,different value.");//三元表达式 判断是否相同
			md5.value="true md5 value from other place";
		}
		else{
			$('#md5value').html("compose the md5 value first");//没生成 就点击验证显示的提示
		}
	}
</script>
</head>
<body>
<div id="logo">
	<img src="/images/logo.png" alt="Logo">
	<h1>wind's page</h1>
	<p><em> a zone 4 a coder </em></p>
</div>
<div id="header">
	<div id="menu">
		<ul>
			<li><a href="/">Home</a></li>
			<li><a href="/resume.html">Resume</a></li>
			<li><a href="/gallery.html">Gallery</a></li>
            <li><a href="/demo.html" class='current'>Demo</a></li>
			<li><a href="/other.html">Other</a></li>
		</ul>
	</div>
    <div id="search">
    	<g:plusone href="http://www.aceyo.com" size="medium"></g:plusone><br />
        <a target="_blank" href="http://wpa.qq.com/msgrd?v=3&uin=562747059&site=qq&menu=yes"><img border="0" width="59" height="16" src="http://wpa.qq.com/pa?p=2:562747059:46" alt="企鹅号" title="企鹅号"></a>
	</div>
</div>
<div id="page">
	<b>js语言MD5加密的. 需要额外的js包. 主要就是是用内部的 hex_md5(str) 和 b64_md5(str) 方法</b>  <a href="/js/md5.min.js" class="button green small" target='_blank'>js下载</a>
	<div style="width:860px;height:340px;border:1px dashed #4999CB;margin:10px 0;padding:10px; font-size:14px; color: green;">
		input a string: <input id="test" value="test">
		<input type="button" value="compose" onClick="compose(test.value,'1')">
		<input type="button" value="compose64" onClick="compose(test.value,'0')"><br/><br />
		md5 value is : <label id="md5value" style=" color:blue"></label><br/><br />
		verify the created value: 
		<input id="md5" onFocus="this.value=''" value="true md5 value from other place" size="40">
		<input type="button" value="verify" onClick="verify(md5)"><br />
	</div>
</div>
<div id="footer">
	<p>Copyright (c) 2011 Aceyo.com. All rights reserved. <br /><img src="http://new.cnzz.com/v1/images/icon/icon.gif" border="0"> <script src="http://s23.cnzz.com/stat.php?id=3684523&web_id=3684523&online=1&show=line"></script></p>
</div>
</body>
</html>